function ajax_page(page) {
    console.log(page);
	$.ajax({
		type:"POST",
		data:$('#list-filter').serialize()+'&p='+page,            
		success: function(data,status){
            //console.log($("#ajax-data").html());
			$("#ajax-data").html(data);
		}
	});
}

//table 表格绑定
$(function(){
	$("tr").click(function(){
		var input=$(this).find("input");
		var t=input.prop("checked");
		input.prop("checked",!t);
	})
	$("tr input[type='checkbox']").click(function(){
		var t=$(this).prop("checked");
		$(this).prop("checked",!t);
	})
})

//表单通用删除
function datadel(url){
	var len=$("input:checkbox:checked").length
	if(len<=0){
		layer.msg('请勾选需要删除的列表',{icon:2,time:2000});
		return false;
	}	
	 layer.confirm('确认要批量删除嘛？',{icon:3},function(index){
        var data= $('#frm').serialize();
        $.post(url,data,function(e){
            if(e.code==1){
                layer.alert(e.msg,{icon:1},function(){
                    location.reload();
                })
            }else{
                layer.msg(e.msg,{icon:5});
            }
        })
	 })
}

/************************************************************* 所有带确认的ajax提交btn ********************************************************/
/* get执行并返回结果，执行后不带跳转 */
$(function () {
	$('body').on('click','.rst-btn',function () {
        var $url = this.href;
        $.get($url, function (data) {
            if (data.code == 1) {
                layer.alert(data.msg, {icon: 6});
            } else {
                layer.alert(data.msg, {icon: 5});
            }
        }, "json");
        return false;
    });
});

/*单项删除*/
$(function () {
	$('body').on('click','.rst-delete-btn',function () {
        var $url = this.href,
            info=$(this).data('info')||'确认删除此项吗？',
         _self=this;
        layer.confirm(info,{icon:3},function(index){
        	layer.close(index);
        	$.get($url, function (data) {
	            if (data.code == 1) {
	            	$(_self).parents("tr").remove();
	                layer.msg(data.msg, {icon: 1});
	            } else {
	                layer.msg(data.msg, {icon: 5});
	            }
	        }, "json");
        })
        return false;
    });
});
/* get执行并返回结果，执行后带跳转 */
$(function () {
	$('body').on('click','.rst-url-btn',function () {
        var $url = this.href;
        $.get($url, function (data) {
            if (data.code==1) {
                layer.alert(data.msg, {icon: 6}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
            } else {
                layer.alert(data.msg, {icon: 5}, function (index) {
                    layer.close(index);
                });
            }
        }, "json");
        return false;
    });
});
/*回车事件绑定*/
$(function(){
    $(document).keydown(function(event){ 
        if(event.keyCode == 13){ //绑定回车 
            $('.Enter-btn').click(); //自动/触发登录按钮 
        } 
    }); 
})

/* 直接跳转 */
$(function () {
	$('body').on('click','.confirm-btn',function () {
        var $url = this.href,
            $info = $(this).data('info');
        layer.confirm($info, {icon: 3}, function (index) {
            layer.close(index);
            window.location.href = $url;
        });
        return false;
    });
});
/* post执行并返回结果，执行后不带跳转 */
$(function () {
	$('body').on('click','.confirm-rst-btn',function () {
        var $url = this.href,
            $info = $(this).data('info');
        layer.confirm($info, {icon: 3}, function (index) {
            layer.close(index);
            $.post($url, {}, function (data) {
                layer.alert(data.msg, {icon: 6});
            }, "json");
        });
        return false;
    });
});
/* get执行并返回结果，执行后带跳转 */
$(function () {
	$('body').on('click','.confirm-rst-url-btn',function () {
        var $url = this.href,
            $info = $(this).data('info');
        layer.confirm($info, {icon: 3}, function (index) {
            layer.close(index);
            $.get($url, function (data) {
                if (data.code==1) {
                    layer.alert(data.msg, {icon: 6}, function (index) {
                        layer.close(index);
                        window.location.href = data.url;
                    });
                } else {
                    layer.alert(data.msg, {icon: 5}, function (index) {
                        layer.close(index);
                    });
                }
            }, "json");
        });
        return false;
    });
});
$(function () {
    $('body').on('click','.confirm-url-btn',function () {
        var $url = this.href,
            $info = $(this).data('info');
        layer.confirm($info, {icon: 3}, function (index) {
            layer.close(index);
            window.location.href = $url;
        });
        return false;
    });
});

/*搜索form*/
$(function () {
    $('body').on('click','.ajax-search-form',function () {
        $.ajax({
            type:"POST",
            data:$(this).parents("form").serialize(),            
            success: function(data,status){
                $("#ajax-data").html(data);
            }
        }); 
        return false;
    });
});
/*搜索type*/
$(function () {
    $('body').on('click','.ajax-search-type',function () {
        $(this).parents("form")[0].reset();
        alert($(this).data('type'));
        $.ajax({
            type:"POST",
            data:{type:$(this).data('type')},            
            success: function(data,status){
                $("#ajax-data").html(data);
            }
        }); 
        return false;
    });
});
/*搜索form显示全部*/
$(function () {
    $('body').on('click','.ajax-display-all',function () {
        $(this).parents("form")[0].reset();
        $.ajax({
            type:"POST",
            data:{},            
            success: function(data,status){
                $("#ajax-data").html(data);
            }
        }); 
        return false;
    });
});
/*清空*/
$(function () {
    $('body').on('click','.ajax-drop',function () {
        $(this).parents("form")[0].reset();
        var url=$(this).parent('a').attr('href');
        $.ajax({
            type:"POST",
            url:url,
            data:{},            
            success: function(data,status){
                layer.alert(data.msg, {icon: 6}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
            }
        }); 
        return false;
    });
});


/*************************************************************************** 所有状态类的ajax提交btn ********************************************************/
/* 审核状态操作 */
$(function () {
    $('body').on('click','.state-btn',function () {
        var $url = this.href,
            val = $(this).data('id'),
            $btn=$(this);
        $.post($url, {x: val}, function (data) {
            if (data.code==1) {
                if (data.msg == '未审') {
                    var a = '<button class="btn btn-minier btn-danger">未审</button>';
                    $btn.children('div').html(a).attr('title','未审');
                    return false;
                } else {
                    var b = '<button class="btn btn-minier btn-yellow">已审</button>';
                    $btn.children('div').html(b).attr('title','已审');
                    return false;
                }
            } else {
                layer.alert(data.msg, {icon: 5});
            }
        }, "json");
        return false;
    });
});
$(function () {
    $('body').on('click','#btnorder',function () {
        var $url=$(this).attr("href");
        if(!$url){
            $url=$(this).parents('form').attr('action');
        }
        $.post($url, $("input.list_order").serialize(), function (data) {
            if (data.code==1) {
                layer.alert(data.msg, {icon: 6}, function (index) {
                    window.location.href = data.url;
                    layer.close(index);
                });
            }else{
                layer.alert(data.msg, {icon: 5}, function (index) {
                    layer.close(index);
                });
            }
        }, "json");
        return false;
    });
});
/* 启用状态操作 */
$(function () {
    $('body').on('click','.open-btn',function () {
        var $url = this.href,
            val = $(this).data('id'),
            title = $(this).data('title'),
            $btn=$(this);
            titles=title.split('|');

        $.post($url, {x: val,title:title}, function (data) {
            if (data.code==1) {
                if (data.msg == titles[1]){
                    var myclass="btn btn-warning";
                } else {
                    var myclass="btn btn-success";
                }
                var a = '<button class="'+myclass+'">'+data.msg+'</button>';

                $btn.html(a).attr('title','已'+data.msg);
                return false;
            } else {
                layer.alert(data.msg, {icon: 5});
            }
        }, "json");
        return false;
    });
});
/******************************************弹出层*******************************************************************/
$(function(){
    $('body').on('click','.layer-btn-open',function(e){
        e.preventDefault();//冒泡阻止
        var url=this.href,
        id = $(this).data('id'),
        w = $(this).data('w'),
        h = $(this).data('h'),
        title = $(this).data('title');
        title=title||'信息设置';
        $.post(url,{id:id},function(str){
            if(str.code==0){
                layer.msg(str.msg,{icon:5,time:2000});
                return;
            }
            layer.open({
              type: 1,
              title:[title,'font-size:18px;background-color:#20222A;color:#fff'],
              skin: '', //加上边框
              area: [w||'60%', h||'60%'], //宽高
              content: str
            });
        })
    })
})


/*****************************************************************************************/
/*点击展开详情*/
$(function () {
    $('body').on('click','.show-details-btn',function (e) {
        e.preventDefault();
        $(this).closest('tr').next().toggleClass('open');
        $(this).find('.ace-icon').toggleClass('fa-angle-double-down').toggleClass('fa-angle-double-up');
    });
});
/*点击展开下级列表*/
$(function () {
    $('body').on('click','.show-list-btn',function (e) {
        e.preventDefault();
        var id= $(this).data('id');
        if($(this).find('.ace-icon').hasClass('fa-angle-double-right')){
            //显示
            $(".fid-"+id).show();
        }else{
            //隐藏
            $(".fid-"+id).hide();
            $('.fid-'+id).find('.ace-icon').toggleClass('fa-angle-double-down').toggleClass('fa-angle-double-right');
            $(".fids-"+id).hide();  
        }
        $(this).find('.ace-icon').toggleClass('fa-angle-double-down').toggleClass('fa-angle-double-right');
    });
});

function chk(){
    var all = document.getElementById("all");
    var mychk = document.getElementsByName("ids[]");
    if(all.checked==true){
        if(mychk.length){
            for(var i=0;i<mychk.length;i++){
                mychk[i].checked = true;
            }
        }
        mychk.chcked=true;
    }else{
        if(mychk.length){
            for(var i=0;i<mychk.length;i++){
                mychk[i].checked = false;
            }
        }
    }
}


function setWidth(className){
    var li = $(className).children('ul').children('li')
    var width = 100/li.length
    $(li).css('width',width+'%');
}